package LW.org.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import LW.org.DToperation.*;
import LW.org.model.Users;
public class BasicOperation extends ActionSupport {
	private static final long serialVersionUID = 1L;
	
	private int id;
	private String pwd;
	private Users newone;
	private String repassword;
	
	
	
	
	
	public String getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public Users getNewone() {
		return newone;
	}

	public void setNewone(Users newone) {
		this.newone = newone;
	}

	public String login()throws Exception{
		
		System.out.println(this.id+"  "+this.pwd);
		operation o = new operation();
		Users res = o.check((int)this.id);
		if(res!=null && res.getPassword().trim().equals(this.pwd))
		{
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("user", res);
			return SUCCESS;
		}
		return ERROR;
	}
	
	public String register()
	{
		Users newone = new Users();
		newone.setName(this.newone.getName());
		newone.setPassword(this.newone.getPassword());
		operation o = new operation();
		Users status = o.addNewone(newone);
		if(status!=null)
		{
			Map<String,Object> status_page = ActionContext.getContext().getSession();
			status_page.put("status", true);
			status_page.put("user", status);
			return SUCCESS;
		}
		return ERROR;
	}

}
